// var arr=$.cookie('arr')?JSON.parse($.cookie('arr')):[];
// //点击登陆事件
// $(".minbox button").on('click',function(){
//     var phone=$(".phone input").val();
//     console.log(phone);
//     var pass=$(".pass input").val();
//     console.log(pass);
//     if( phone && pass ){
//         //判断该用户是否存在
//         var res = arr.some(function(item){
//             return phone == item.phone && pass == item.pass;
//         })
//         if(res){
//            $('.minbox button a').attr('href',"../html/小米有品首页.html")
//         }else{
//             alert('登陆失败');
//         }
//     }
// })

let oBtnLogin = document.getElementById("btnLogin");
let oUserPass = document.getElementById("userpass"); 
let oUserName = document.getElementById("username"); 

oBtnLogin.onclick = function(){

    var queren=$('.zhuceanniu').prop('checked')
    if(queren==true){
        let xhr = new XMLHttpRequest();
        xhr.open("post","login.php",true);
        var names=$('.phone .val').val();
        
        xhr.onreadystatechange = function(){
            if(xhr.readyState==4 && xhr.status==200){
               if(xhr.responseText.trim()=="success"){
                $.cookie('username',JSON.stringify(names))
                alert("登陆成功")
                location.href='../html/index.html';
                console.log(names);
                   
               }else{
                  
                  
                   alert("登录失败,用户名或者密码错误");
               }
            }
        }
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    
        let str = "username="+oUserName.value+"&userpass="+oUserPass.value;
        xhr.send(str);
    }else if(queren==false){
        window.alert('请先点击复选框')
    }


}

